package edu.gatech.app4args;

import java.awt.Color;

import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

/**
 * Controls the Overview slides. Only does additions for now, but eventually
 * will handle deletions and rearrangements of slide order.
 *
 * @author Andrew Lunsford
 */
public class OverviewPanel extends JPanel{
	/** Holds all Overview Slide objects */
	private ArrayList<OverviewSlide> overviewSlides;
	/** Indicates the index of the currently selected slide */
	private int currentSlide;

	/**
	 * Creates an instance of OverviewPanel and sets the layout. Also creates
	 * the array list to hold all overview slides. A reference to the Main
	 * class allows the panel to update the selected slide and call an update
	 * when it changes.
	 *
	 * @param ref reference to the Main class
	 */
	public OverviewPanel(Main ref){
		this.setAlignmentX(LEFT_ALIGNMENT);
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		overviewSlides = new ArrayList<OverviewSlide>();
		currentSlide = -1;
	}

	/**
	 * Creates a new OverviewSlide object and adds it to overviewSlides. Sets
	 * the current slide so that the background will indicate the new slide
	 * is selected.
	 *
	 * @param ref a reference to the Main class to pass to the OverviewSlide
	 * @param slidetype the type of OverviewSlide to create
	 * @param slideNumber the number of the OverviewSlide
	 */
	public void addOverviewSlide(Main ref, int slidetype, int slideNumber){
		overviewSlides.add( new OverviewSlide(ref, slidetype, slideNumber));
		this.add(overviewSlides.get(overviewSlides.size()-1));
		this.setCurrentSlide(slideNumber-1);
		this.revalidate();
		this.repaint();
	}

	/**
	 * Resets the background of the previous slide to null/transparent, updates
	 * to the new current slide, and sets its background to the selection
	 * color to indicate it is the current slide.
	 *
	 * @param slideNumber
	 */
	public void setCurrentSlide(int slideNumber){
		if(!(currentSlide<0))
			overviewSlides.get(currentSlide).setBackground(null);
		currentSlide = slideNumber;
		overviewSlides.get(currentSlide).setBackground(Color.getHSBColor(210.0f/360.0f, 0.6f, 0.8f));
		this.revalidate();
		this.repaint();
	}

	public ArrayList<OverviewSlide> getOverviewSlides() {
		return overviewSlides;
	}

	public int getCurrentSlide() {
		return currentSlide;
	}
}
